"""
URL configuration for TestHub project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from rest_framework import permissions
import os

# 定义 Swagger 文档视图
schema_view = get_schema_view(
    openapi.Info(
        title="API 文档",
        default_version='v1',
        description="自动化测试平台接口文档",
        contact=openapi.Contact(email="2750826557@qq.com"),
    ),
    public=True,
    permission_classes=(permissions.AllowAny,),  # 控制文档访问权限
)
urlpatterns = [
    path("admin/", admin.site.urls),
    path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='swagger-ui'),
    path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='redoc'),
    path('user/', include("user.urls")),
    path('department/', include("department.urls")),
    path('project/', include("project.urls")),
    path('case_api/', include("case_api.urls")),
    path('suite/', include("suite.urls")),
    path('logs/', include("logs.urls")),
    
    # 添加静态报告访问路径
    path('reports/', include('django.contrib.staticfiles.urls')),
]

# 开发环境下提供报告访问
if settings.DEBUG:
    # 提供对 PyAllure/reports 目录的访问
    urlpatterns += static('/reports/', document_root=os.path.join(settings.BASE_DIR, 'PyAllure', 'reports'))
    
    # 提供对 PyAllure/temps 目录的访问（包含原始测试结果数据）
    urlpatterns += static('/allure-results/', document_root=os.path.join(settings.BASE_DIR, 'PyAllure', 'temps'))
